package com.dl.test;

import java.sql.*;

public class jdbc {
    public static void main(String[] args) throws SQLException {
        String url="jdbc:mysql://localhost:3306/hotel?serverTimezone=UTC &&useSSL=false";
        String username="root";
        String password="123456";
        Connection conn=null;
        Statement stmt=null;
        ResultSet rs=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn= DriverManager.getConnection(url, username, password);
            stmt=conn.createStatement();
            String sql="select * from customer";
            String sql2="insert into student(id,name,password,phonenumber,idcard,email) values(5,'lgj','123','123456','430723','148@qq.com')";
            String sql3="delete from student where sid=5";
            String sql4="update student set sname='lsb' where sid=2";
            //stmt.executeUpdate(sql4);
            rs=stmt.executeQuery(sql);
            System.out.println("id  |name  |age");
            while(rs.next()){
                int id=rs.getInt("id");
                String sname=rs.getString("name");
                int age=rs.getInt("password");
                System.out.println(id+"    "+sname+"    "+age);
            }
            rs.close();
            stmt.close();
            conn.close();


        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }}}


